package com.edu.user.utils;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;

/*
* 发送短信
*
* */
public class SMSUtils {
    public static void sendMessage(String signName,String templateCode,String phoneNumbers,String param){
        DefaultProfile profile =
                DefaultProfile.getProfile("cn-hangzhou", "LTAI5tNWWGLojhf13StBkAUd", "gzJ6hjfY2YDA6LFY2ezEhOyHY8SvRn");
        IAcsClient client = new DefaultAcsClient(profile);
        SendSmsRequest request = new SendSmsRequest();
        request.setRegionId("cn-hangzhou");
        request.setPhoneNumbers(phoneNumbers);
        request.setSignName(signName); // 短信签名
        request.setTemplateCode(templateCode);
        request.setTemplateParam("{\"code\":\""+param+"\"}");

        SendSmsResponse acsResponse = null;
        try {
            acsResponse = client.getAcsResponse(request);
            System.out.println("短信发送成功");

        } catch (ClientException e) {
            throw new RuntimeException(e);
        }


    }
}
